package com.df.zkservice.service;

import com.df.core.dao.UserRepository;
import com.df.core.entity.TestEntity;
import com.df.core.entity.User;
import com.df.core.service.DfUtil;
import com.df.core.service.TestCoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by DFx on 2016/9/16.
 */


@RestController
@RequestMapping(value = "/testService", method = RequestMethod.POST)
public class TestServiceImpl {

    private String msg = "testMsg";

    private TestCoreService testService;

    @Autowired
    private UserRepository userRepository;

    @RequestMapping(value = "/getMsg", method = RequestMethod.POST)
    public String getMsg() {
        DfUtil.test();
        return msg + "_SS";
    }

    @RequestMapping(value = "/getUserModel", method = RequestMethod.POST)
    public TestEntity getUserModel(@RequestParam(value = "id") int id) {
        System.out.println(id);
        TestEntity t = new TestEntity();
        t.setId(1L);
        t.setThisTime(new Date());
        t.setUserName("testUserName");
        return t;
    }


    @RequestMapping(value = "/hi", method = RequestMethod.GET)
    public String hi() {
        DfUtil.test();
        return "this.hi";
    }


    @RequestMapping(path = "/getTra", method = RequestMethod.TRACE)
    String getTra() {
        return "thisTraSS";
    }

    @RequestMapping(path = "/getOpt", method = RequestMethod.OPTIONS)
    String getOpt() {
        return "thisOptSS";
    }


    @RequestMapping(value = "/testSave", method = RequestMethod.POST)
    @Transactional
    public Long testSave() {
        User user = userRepository.save(new User("testUserAA", new Date()));
        System.out.println(userRepository.findUser("testUserAA"));
        userRepository.findUserModel("testUserAA");
        return user.getId();
    }
}
